import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [

  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {title: '主页', icon: 'dashboard'}
    }]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/example/table',
    name: 'User',
    meta: {title: '住户管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: '/useradd',
        name: 'useradd',
        component: () => import('@/views/UserAdd'),
        meta: {title: '新增住户', icon: 'el-icon-plus'}
      },
      {
        path: '/userlist',
        name: 'userlist',
        component: () => import('@/views/UserList'),
        meta: {title: '住户列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/usersearch',
        name: 'usersearch',
        component: () => import('@/views/UserSearch'),
        meta: {title: '搜索住户', icon: 'el-icon-plus'}
      },
      {
        path: '/userupdate',
        name: 'userupdate',
        component: () => import('@/views/UserUpdate'),
        meta: {title: '修改住户信息', icon: 'table'},
        //修改
        hidden: true
      }, {
        path: '/userdetail',
        name: 'userdetail',
        component: () => import('@/views/UserDetail'),
        meta: {title: '住户详情', icon: 'el-icon-plus'},
        hidden: true
      }, {
        path: '/userdetialupdate',
        name: 'userdetialupdate',
        component: () => import('@/views/UserDetailUpdate'),
        meta: {title: '修改住户详情', icon: 'el-icon-plus'},
        hidden: true
      },
      {
        path: '/lovelycaradd',
        name: 'lovelycaradd',
        component: () => import('@/views/LovelyCarAdd'),
        meta: {title: '爱车注册', icon: 'el-icon-plus'},

      },
      {
        path: '/lovelycardetail',
        name: 'lovelycardetail',
        component: () => import('@/views/LovelyCarDetail'),
        meta: {title: '爱车详情', icon: 'el-icon-plus'},
        hidden: true
      },
      {
        path: '/userlog',
        name: 'userlog',
        component: () => import('@/views/UserList'),
        meta: {title: '用户日志', icon: 'table'}
      }
    ]
  }, {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: {title: 'Example', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'table',
        name: 'Table',
        component: () => import('@/views/table/index'),
        meta: {title: 'Table', icon: 'table'}
      },
      {
        path: 'tree',
        name: 'Tree',
        component: () => import('@/views/tree/index'),
        meta: {title: 'Tree', icon: 'tree'}
      }
    ]
  },

  {
    path: '/form',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: {title: 'Form', icon: 'form'}
      }
    ]
  },
  {
    path: '/car',
    component: Layout,
    redirect: '/car/table',
    name: 'Car',
    meta: {title: '车辆管理', icon: 'el-icon-aim'},
    children: [
      {
        path: '/carlist',
        name: 'carlist',
        component: () => import('@/views/CarList'),
        meta: {title: '车辆列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/caradd',
        name: 'caradd',
        component: () => import('@/views/CarAdd'),
        meta: {title: '车辆新增', icon: 'el-icon-circleplusfilled'}
      },
      {
        path: '/carupdate',
        name: 'carupdate',
        component: () => import('@/views/CarUpdate'),
        meta: {title: '车辆修改', icon: 'el-icon-circleplusfilled'},
        hidden: true
      }
    ]
  },


  {
    path: '/carSpace',
    component: Layout,
    redirect: '/carSpace/table',
    name: 'CarSpace',
    meta: {title: '车位管理', icon: 'el-icon-place'},
    children: [
      {
        path: '/carSpacelist',
        name: 'carSpacelist',
        component: () => import('@/views/CarSpaceList'),
        meta: {title: '车位列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/carSpaceadd',
        name: 'carSpaceadd',
        component: () => import('@/views/CarSpaceAdd'),
        meta: {title: '车位新增', icon: 'table'}
      },
      {
        path: '/carSpaceUpdate',
        name: 'carSpaceUpdate',
        component: () => import('@/views/CarSpaceUpdate'),
        meta: {title: '车位修改', icon: 'el-icon-circleplusfilled'},
        hidden: true
      }
    ]
  },
  {
    path: '/information',
    component: Layout,
    redirect: '/information/table',
    name: 'Example',
    meta: {title: '信息管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: '/informationadd',
        name: 'informationadd',
        component: () => import('@/views/InformationAdd'),
        meta: {title: '信息新增', icon: 'el-icon-plus'}
      },
      {
        path: '/informationlist',
        name: 'informationlist',
        component: () => import('@/views/InformationList'),
        meta: {title: '信息列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/informationupdate',
        name: 'informationupdate',
        component: () => import('@/views/InformationUpdate'),
        meta: {title: '信息更新', icon: 'el-icon-s-order'},
        hidden: true
      }

    ]
  },
  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/table',
  //   name: 'Example',
  //   meta: { title: '用户管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: '/useradd',
  //       name: 'useradd',
  //       component: () => import('@/views/UserAdd'),
  //       meta: { title: '用户新增', icon: 'el-icon-plus' }
  //     },
  //     {
  //       path: '/userlist',
  //       name: 'userlist',
  //       component: () => import('@/views/UserList'),
  //       meta: { title: '用户列表', icon: 'el-icon-s-order' }
  //     },
  //     {
  //       path: '/userlog',
  //       name: 'userlog',
  //       component: () => import('@/views/UserList'),
  //       meta: { title: '用户日志', icon: 'table' }
  //     }
  //   ]
  // }, {
  //   path: '/dept',
  //   component: Layout,
  //   redirect: '/dept/table',
  //   name: 'Dept',
  //   meta: { title: '部门管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: '/deptadd',
  //       name: 'deptadd',
  //       component: () => import('@/views/UserAdd'),
  //       meta: { title: '部门新增', icon: 'table' }
  //     },
  //     {
  //       path: '/deptlist',
  //       name: 'deptlist',
  //       component: () => import('@/views/UserList'),
  //       meta: { title: '部门列表', icon: 'table' }
  //     }
  //   ]
  // },
  {
    path: '/ordervue',
    component: Layout,
    redirect: '/ordervue/table',
    name: 'Example',
    meta: {title: '缴费管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: '/orderadd',
        name: 'orderadd',
        component: () => import('@/views/OrderAdd'),
        meta: {title: '订单新增', icon: 'el-icon-plus'}
      },
      {
        path: '/orderlist',
        name: 'orderlist',
        component: () => import('@/views/OrderList'),
        meta: {title: '订单列表', icon: 'el-icon-s-order'}
      },
      {
        path: '/orderupdate',
        component: () => import('@/views/OrderUpdate'),
        meta: {title: '订单修改', icon: 'table'},
        hidden: true
      }
    ]
  },

  {
    path: '/house',
    component: Layout,
    redirect: '/house/table',
    name: 'House',
    meta: {title: '房屋管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: '/houseadd',
        name: 'houseadd',
        component: () => import('@/views/HouseAdd'),
        meta: {title: '房屋新增', icon: 'table'}
      }, {
        path: '/houselist',
        name: 'houselist',
        component: () => import('@/views/HouseList'),
        meta: {title: '房屋列表', icon: 'table'}
      }, {
        path: '/houseupdate',
        component: () => import('@/views/HouseUpdate'),
        meta: {title: '房屋修改', icon: 'table'},
        hidden: true
      }
    ]
  }, {
    path: '/emp',
    component: Layout,
    redirect: '/emp/table',
    name: 'Emp',
    meta: {title: '员工管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: '/empadd',
        name: 'empadd',
        component: () => import('@/views/EmpAdd'),
        meta: {title: '员工新增', icon: 'table'}
      }, {
        path: '/emplist',
        name: 'emplist',
        component: () => import('@/views/EmpList'),
        meta: {title: '员工列表', icon: 'table'}
      }, {
        path: '/empupdate',
        component: () => import('@/views/EmpUpdate'),
        meta: {title: '员工修改', icon: 'table'},
        hidden: true
      }
    ]
  },

  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    meta: {
      title: 'Nested',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: {title: 'Menu1'},
        children: [
          {
            path: 'menu1-1',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'Menu1-1',
            meta: {title: 'Menu1-1'}
          },
          {
            path: 'menu1-2',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'Menu1-2',
            meta: {title: 'Menu1-2'},
            children: [
              {
                path: 'menu1-2-1',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                name: 'Menu1-2-1',
                meta: {title: 'Menu1-2-1'}
              },
              {
                path: 'menu1-2-2',
                component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                name: 'Menu1-2-2',
                meta: {title: 'Menu1-2-2'}
              }
            ]
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: {title: 'Menu1-3'}
          }
        ]
      },
      {
        path: 'menu2',
        component: () => import('@/views/nested/menu2/index'),
        name: 'Menu2',
        meta: {title: 'menu2'}
      }
    ]
  },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: {title: 'External Link', icon: 'link'}
      }
    ]
  },

  // 404 page must be placed at the end !!!
  {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
